package com.demo.Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name = "LoginServlet",urlPatterns = "/LoginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        /*response.setContentType("text/html; charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        PrintWriter out=response.getWriter();
        String name = request.getParameter("name");
        String password = request.getParameter("password");
         if(name.equals("admin")&&password.equals("123")){

             out.print("登陆成功");
         }else{
             out.print("登陆失败");
         }*/
    }
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String name = request.getParameter("name");
        String password = request.getParameter("password");

        if ("admin".equals(name) && "123".equals(password)) {
            request.getRequestDispatcher("success.jsp").forward(request, response);
        }
        else{
            response.sendRedirect("fail.jsp");
        }



    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

    }

    public LoginServlet(){
        System.out.println("LoginServlet 构造方法 被调用");
    }
    public void init(ServletConfig config) {
        System.out.println("init(ServletConfig)");
    }
    public void destroy() {
        System.out.println("destroy()");
    }
}